package com.yenlien.traceyun.breed.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSONObject;
import com.yenlien.traceyun.breed.entity.Out;
import com.yenlien.traceyun.breed.service.OutService;
import com.yenlien.traceyun.business.interceptor.DataAuth;
import com.yenlien.traceyun.webase.controller.BaseController;

/**
 * 出场控制层
 *
 * @author maybe
 * @date 2020年9月25日
 */
@RestController
@RequestMapping("/out")
public class OutController extends BaseController {
    @Autowired
    private OutService outService;

    //分页查询列表
    @DataAuth
    @RequestMapping(value = "/findByList", method = RequestMethod.POST)
    public Object findByList(@RequestBody JSONObject params) {
        Out out = new Out();
        out.setBreedId(params.getString("breedId"));
        out.setCustomer(params.getString("searchName"));
        out.setOutBatch(params.getString("searchName"));
        out.setPage(params.getIntValue("page"));
        out.setPageSize(params.getIntValue("pageSize"));
        return buildPage(outService.findByList(out));
    }

    //出场
    @RequestMapping(value = "/save", method = RequestMethod.POST)
    public Object save(@RequestBody Out out) {
        outService.save(out);
        return success("success");
    }

    //根据ID查询出场详情
    @RequestMapping(value = "/findById/{id}", method = RequestMethod.GET)
    public Object findById(@PathVariable("id") String id) {
        return success(outService.findById(id));
    }

    //根据类型和编码查询码是否出库
    @RequestMapping(value = "/findByTypeAndCode", method = RequestMethod.POST)
    public Object findByTypeAndCode(@RequestBody JSONObject params) {
        return success(outService.findByTypeAndCode(params));
    }
}
